//
//  AudioFiles.swift
//  Scaner
//
//  Created by liyahao on 2025/4/14.
//

import UIKit
import SQLite

struct AudioFiles: Identifiable {
    var id: Int
    var name: String
    var duration: Int
    var path: String
    var group: String // 分组
    var asr: String? // 语音识别文字
    var tsp: String // 时间戳
    var location: String? // 地点名称
    var lat: String? // 纬度
    var lng: String? // 经度
}

extension AudioFiles: SQLProtocol {
    static var table = SQLite.Table("audio")
    
    // 创建数据库
    static var tableCreate: String {
        let intKeys: [String] = ["duration"]
        let strKeys: [String] = ["name","path","tsp", "group"]
        let optKeys: [String] = ["asr","location","lat","lng"]
        return Self.table.create(ifNotExists: true) { table in
            table.column(SQLite.Expression<Int64>("id"), primaryKey: true)
            intKeys.forEach { table.column(SQLite.Expression<Int>($0)) }
            strKeys.forEach { table.column(SQLite.Expression<String>($0)) }
            optKeys.forEach { table.column(SQLite.Expression<String?>($0)) }
        }
    }
    
    static var samples: [AudioFiles] {
        return [AudioFiles(
            id: 0,
            name: "新录音1",
            duration: 10,
            path: "audio.lastPathComponent",
            group: "未分组",
            asr: "语音识别技术属于人工智能方向的一个重要分支，涉及许多学科，如信号处理、计算机科学、语言学、声学、生理学、心理学等，是人机自然交互技术中的关键环节。 [5]语音识别较语音合成而言，技术上要复杂，但应用却更加广泛。语音识别ASR的最大优势在于使得人机用户界面更加自然和容易使用。",
            tsp: Date.tspString,
            location: "金桥创意谷"),
        AudioFiles(
            id: 2,
            name: "新录音1",
            duration: 10,
            path: "audio.lastPathComponent",
            group: "未分组",
            tsp: Date.tspString,
            location: "金桥创意谷"),
        AudioFiles(
            id: 3,
            name: "新录音1",
            duration: 10,
            path: "audio.lastPathComponent",
            group: "未分组",
            asr: "语音识别技术，也被称为自动语音识别（Automatic Speech Recognition，ASR）",
            tsp: Date.tspString,
            location: "金桥创意谷"),
        AudioFiles(
            id: 4,
            name: "新录音1",
            duration: 10,
            path: "audio.lastPathComponent",
            group: "未分组",
            tsp: Date.tspString,
            location: "金桥创意谷")]
    }
}
